home *** CD-ROM | disk | FTP | other *** search
/ The Missionary / Missionary, The - Issue 1 (1991-11)(ABOTS PD)(PD).adf / Technical / Intro.ASM < prev    next >
Assembly Source File  |  1991-11-07  |  14KB  |  663 lines

  1.   
  2.      OPT C-            ;Turn off case sensitivity
  3.     
  4.     Section MISSION,CODE_C    ;Make amiga_dos load the whole prg to chipram
  5.  
  6. *******************************************************************
  7.  
  8. Cmove    MACRO
  9.     dc.w \2,\1
  10.     ENDM
  11.         
  12. Cwait    MACRO
  13.     dc.w \2<<8!\1!1,$fffe
  14.     ENDM
  15.  
  16. Blitwait MACRO
  17. bw_\@    btst #14,dmaconr(a5)
  18.     bne.s bw_\@
  19.     ENDM
  20.     
  21. CatchVB MACRO
  22. vb1_\@:
  23.     btst #0,vposr+1(a5)
  24.     beq.s vb1_\@
  25. vb2_\@:
  26.     btst #0,vposr+1(a5)
  27.     bne.s vb2_\@
  28.     ENDM
  29.     
  30. *******************************************************************
  31.     
  32. start:    
  33.     move.l    #$dff000,a5        ;address of custom regs.
  34.     catchvb
  35.     blitwait
  36.     jsr    takesys            ;kill the operating system
  37.     move.w    #$8240,dmacon(a5)
  38.     move.l    #0,0            ;for people with an A590
  39.             
  40. *******************************************************************
  41.     
  42. makescreens:    
  43.     move.l    #piccy+(0*planesize),d0        ;address of picture
  44.     move.w    d0,plane1l            ;store in copper list
  45.     swap    d0
  46.     move.w    d0,plane1h
  47.     move.l    #piccy+(1*planesize),d0        ;second plane
  48.     move.w    d0,plane2l
  49.     swap    d0
  50.     move.w    d0,plane2h
  51.     move.l    #piccy+(2*planesize),d0        ;third plane
  52.     move.w    d0,plane3l
  53.     swap    d0
  54.     move.w    d0,plane3h    
  55.     move.l    #piccy+(3*planesize),d0        ;fourth plane
  56.     move.w    d0,plane4l
  57.     swap    d0
  58.     move.w    d0,plane4h
  59.     
  60. *******************************************************************
  61.  
  62. set_dma:
  63.     catchvb
  64.     blitwait
  65.     move.w    #$02e0,dmacon(a5)
  66.     move.w    #$87e0,dmacon(a5)    ;turn on blitter-nasty,
  67.                     ;master DMA, bitplane DMA,
  68.                     ;copper, blitter + sprite DMA
  69.  
  70. *******************************************************************
  71.     
  72. title:
  73.     catchvb                ;wait for vertical blank
  74.     blitwait            ;wait for blitter to be free
  75.     move.w    #$01a0,dmacon(a5)
  76.     move.l    #main_copper,cop1lc(a5)    ;point copper list to our
  77.     move.w    #$ff,copjmp1(a5)    ;custom copper list
  78.     move.w    #$81a0,dmacon(a5)
  79.     move.w    #$4010,intena(a5)    ;disable ints.    
  80.     move.l    #main_int,$6c        ;point to add. of our routine
  81.     move    #$c010,intena(a5)    ;re-enable interrupts
  82.     
  83.     move.w    #2,curspeed
  84.     move.w    #2,palspeed
  85.     
  86.     move.w    #18,d7
  87. fade_cols:
  88.     move.w    #2,int_occur        
  89. cols_wait:
  90.     cmpi.w    #0,int_occur        ;wait until two frames have gone
  91.     bne    cols_wait
  92.     lea    colours,a0        ;set up fade routine
  93.     lea    ac_pal,a1        ;by pointing to our palette
  94.     lea    normal_colours,a2
  95.     lea    palette,a3
  96.     move.w    #15,d6
  97. set_palette:
  98.     move.w    (a0),(a1)+        ;copy present colours to fade 
  99.     move.w    (a2)+,(a3)+        ;routine
  100.     add.w    #4,a0
  101.     dbra    d6,set_palette
  102.     
  103.     move.w    #15,d0            
  104.     bsr    palchange        ;call fade routine
  105.     
  106.     lea    ac_pal,a0
  107.     lea    colours,a1
  108.     move.w    #15,d6
  109. copy_colours:
  110.     move.w    (a0)+,(a1)        ;now copy colours back to
  111.     add.w    #4,a1            ;our copperlist
  112.     dbra    d6,copy_colours
  113.     dbra    d7,fade_cols
  114.  
  115. *******************************************************************
  116.  
  117. main:
  118.     btst    #7,ciaapra        ;is the joystick fire pressed?
  119.     beq    fade_off        ;yes, so exit
  120.     btst    #10,$dff016        ;what about the right mouse?
  121.     beq    fade_off        ;if that is pressed, exit
  122.     btst    #6,ciaapra        ;what about left mouse then?
  123.     bne    main            ;nope, fingers are free!
  124.  
  125. fade_off:
  126.     move.w    #2,curspeed        ;set up fade routine again
  127.     move.w    #2,palspeed
  128.     
  129.     move.w    #15,d7
  130. fade_cols2:
  131.     move.w    #2,int_occur
  132. cols_wait2:
  133.     cmpi.w    #0,int_occur
  134.     bne    cols_wait2
  135.     lea    colours,a0
  136.     lea    ac_pal,a1
  137.     lea    black_colours,a2
  138.     lea    palette,a3
  139.     move.w    #15,d6
  140. set_palette2:
  141.     move.w    (a0),(a1)+        ;copy present colours
  142.     move.w    (a2)+,(a3)+
  143.     add.w    #4,a0
  144.     dbra    d6,set_palette2
  145.     
  146.     move.w    #15,d0
  147.     bsr    palchange        ;call fade off routine
  148.         
  149.     lea    ac_pal,a0
  150.     lea    colours,a1
  151.     move.w    #15,d6
  152. copy_colours2:
  153.     move.w    (a0)+,(a1)        ;copy colours into clist
  154.     add.w    #4,a1
  155.     dbra    d6,copy_colours2
  156.     dbra    d7,fade_cols2
  157.     
  158. *******************************************************************
  159.  
  160. zzap:    
  161.     catchvb
  162.     blitwait    
  163.     jsr    freesys            ;re-enable the op. system
  164.  
  165. ende:
  166.     clr.l    d0            ;and return to DOS!
  167.     rts
  168.         
  169. *******************************************************************
  170.  
  171. * This routine uses two tables - 
  172. *   "Palette"  -- Holds the user's palette to change TO
  173. *   "Ac_Pal"   -- The actual palette at the moment. (Internal)
  174.  
  175. * The user can change the speed by writing a WORD value to
  176. * PalSpeed. The value designates 50ths of a second between each change.
  177.  
  178. Palchange:
  179.     movem.l    d0-d7/a0-a6,-(SP)    ; Preserve registers
  180.     move.w    #0,done_pal
  181.     sub.w    #1,CurSpeed
  182.     beq    PalOK
  183.  
  184.     bra    Pal006
  185. PalOK:
  186.     move.w    #1,done_pal
  187.     move.w    PalSpeed,CurSpeed
  188.     lea    Palette(pc),a0    ; User's Palette
  189.     lea    Ac_Pal(pc),a1    ; Actual (current) palette
  190.  
  191. Pal001:
  192. * D1 holds red pigment, d2 holds green, d3 holds blue
  193.     move.w    (a0)+,d1    ; Load user's color
  194.     move.w    d1,d2
  195.     move.w    d1,d3
  196.     and.w    #$f00,d1
  197.     and.w    #$0f0,d2
  198.     and.w    #$00f,d3
  199.     
  200. * Now for the Actual Palette.
  201.     move.w    (a1),d4    ; Don't incr., we re-write d4 later
  202.     move.w    d4,d5
  203.     move.w    d4,d6
  204.     and.w    #$f00,d4
  205.     and.w    #$0f0,d5
  206.     and.w    #$00f,d6
  207.     
  208. * OK let's convert that color!
  209.     cmp.w    d1,d4
  210.     blt.s    .Rless    ; if D4 is less than D1
  211.     bgt.s    .Rmore
  212.     bra.s    .Rfin
  213.     
  214. .Rless:
  215.     add.w    #$100,d4
  216.     bra.s    .Rfin
  217. .Rmore:
  218.     sub.w    #$100,d4
  219. .Rfin:
  220.     cmp.w    d2,d5
  221.     blt.s    .Gless    ; if D5 is less than D2
  222.     bgt.s    .Gmore
  223.     bra.s    .Gfin
  224.     
  225. .Gless:
  226.     add.w    #$010,d5
  227.     bra.s    .Gfin
  228. .Gmore:
  229.     sub.w    #$010,d5
  230. .Gfin:
  231.     cmp.w    d3,d6
  232.     blt.s    .Bless    ; if D6 is less than D3
  233.     bgt.s    .Bmore
  234.     bra.s    .Bfin
  235.     
  236. .Bless:
  237.     add.w    #$001,d6
  238.     bra.s    .Bfin
  239. .Bmore:
  240.     sub.w    #$001,d6
  241. .Bfin:    
  242. * Now to convert Actual Palette base colors back again,
  243.     or.w    d5,d4
  244.     or.w    d6,d4    ; D4 holds new color
  245.     move.w    d4,(a1)+
  246.     
  247.     dbf    d0,Pal001
  248.     
  249. * Note, ChangePal.ASM Doesn't do anything with Ac_Pal, It's
  250. * up to you to do what you want to do with it to allow
  251. *greater flexibility.
  252.  
  253. Pal006:
  254.     movem.l    (SP)+,d0-d7/a0-a6    ; restore registers
  255.     RTS
  256.     
  257.     
  258. Palette    ds.w    32
  259. Ac_Pal    ds.w    32
  260.  
  261. PalSpeed:    dc.w    2    ; Default speed : every OTHER frame
  262. CurSpeed:    dc.w    2    ; (This to be the best speed)
  263.     
  264. done_pal:    dc.w    0
  265.  
  266. *******************************************************************
  267.  
  268. main_int:
  269.     movem.l    d0-d7/a0-a6,-(sp)
  270.     lea    $dff000,a5
  271.     and    #$10,intreqr(a5)    ;is this a copper int.?
  272.     beq    main_out        ;no, so exit
  273.     move.w    #$10,intreq(a5)        ;clear interrupt flag
  274.  
  275.     cmpi.w    #0,int_occur
  276.     beq    main_out
  277.     sub.w    #1,int_occur
  278. main_out:
  279.     movem.l    (sp)+,d0-d7/a0-a6
  280.  
  281.     rte
  282.  
  283. int_occur:    dc.w    0
  284.  
  285. *******************************************************************
  286. *           The next bit is our custom COPPERLIST               *
  287. *******************************************************************
  288.  
  289. main_copper:
  290.     dc.w    bplcon1,0        ;standard screen
  291.     dc.w    bpl1mod,0,bpl2mod,0    ;no modulos
  292.     dc.w    bplcon0,$4200        ;4 bitplanes
  293.     dc.w    bplcon2,$0        ;normal priority
  294.         
  295.     dc.w    diwstrt,$2c81
  296.     dc.w    diwstop,$2cc1
  297.     dc.w    ddfstrt,$0038
  298.     dc.w    ddfstop,$00d0
  299.     dc.w    spr0pth            ;these are the sprite
  300. sp0h    dc.w    0            ;pointers. We have set
  301.     dc.w    spr0ptl            ;them to point to 0
  302. sp0l:    dc.w    0            ;as we are not using them
  303.     dc.w    spr1pth
  304. sp1h:    dc.w    0
  305.     dc.w    spr1ptl
  306. sp1l:    dc.w    0
  307.     dc.w    spr2pth
  308. sp2h:    dc.w    0
  309.     dc.w    spr2ptl
  310. sp2l:    dc.w    0
  311.     dc.w    spr3pth
  312. sp3h:    dc.w    0
  313.     dc.w    spr3ptl
  314. sp3l:    dc.w    0
  315.     dc.w    spr4pth
  316. sp4h:    dc.w    0
  317.     dc.w    spr4ptl
  318. sp4l:    dc.w    0
  319.     dc.w    spr5pth
  320. sp5h:    dc.w    0
  321.     dc.w    spr5ptl
  322. sp5l:    dc.w    0
  323.     dc.w    spr6pth
  324. sp6h:    dc.w    0
  325.     dc.w    spr6ptl
  326. sp6l:    dc.w    0
  327.     dc.w    spr7pth
  328. sp7h:    dc.w    0
  329.     dc.w    spr7ptl
  330. sp7l:    dc.w    0
  331.  
  332.     dc.w    bpl1pth            ;these are the bitplane
  333. plane1h    dc.w    0            ;pointers
  334.     dc.w    bpl1ptl
  335. plane1l    dc.w    0
  336.     dc.w    bpl2pth
  337. plane2h    dc.w    0
  338.     dc.w    bpl2ptl
  339. plane2l    dc.w    0
  340.     dc.w    bpl3pth
  341. plane3h    dc.w    0
  342.     dc.w    bpl3ptl
  343. plane3l    dc.w    0    
  344.     dc.w    bpl4pth
  345. plane4h    dc.w    0
  346.     dc.w    bpl4ptl
  347. plane4l    dc.w    0    
  348.  
  349.  
  350. ;there now follows the screen colours, in the following order:-
  351. ;1 WORD colour offset, then 1 WORD containing the colour data
  352.  
  353.     dc.w col0
  354. colours:
  355.     dc.w $0000,col1,$0000,col2,$0000,col3,$0000
  356.     dc.w col4,$0000,col5,$0000,col6,$0000,col7,$0000
  357.     dc.w col8,$0000,col9,$0000,col10,$0000,col11,$0000
  358.     dc.w col12,$0000,col13,$0000,col14,$0000,col15,$0000
  359.  
  360.     dc.w    $ff0f,$fffe,$ffdd,$fffe ;use copper in PAL area
  361.     
  362.     cwait    0,51
  363.     dc.w    intreq,$8010
  364.     cwait    255,254
  365.  
  366. *******************************************************************
  367.  
  368. normal_colours:
  369.     dc.w $0000,$0c73,$0976,$0a87,$0654,$0330,$0430,$0430
  370.     dc.w $0530,$0740,$0840,$0950,$0a51,$0a62,$0643,$0444
  371. black_colours:
  372.     dc.w 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  373.  
  374. *****************************************************************************
  375. * TAKESYS and FREESYS were written by P.R.BRAIN (GARION) to safely
  376. * take down and restore the operating system. Thanks to Paul for
  377. * allowing us to use them.
  378. *****************************************************************************
  379. * TAKESYS will disable the OS interrupts and replace with custom drivers
  380. * Also saves out the DMA control status...
  381. * Returns with all Dma and all interrupts OFF
  382. *****************************************************************************
  383.  
  384. Newvects dc.l lev1,lev2,lev3,lev4,lev5,lev6,lev7
  385. Oldvects ds.l 7
  386. OldTAh     dc.b 0
  387. OldTAl     dc.b 0
  388. Oldcra     dc.b 0
  389.     even
  390. Oldintreq dc.w 0
  391. Oldintena dc.w 0
  392. Olddmacon dc.w 0
  393.     
  394. gfxname    dc.b    "graphics.library",0
  395. syscop1 dc.l  0
  396. syscop2 dc.l  0
  397.  
  398. takesys:
  399.     move.l 4.w,a6
  400.     jsr forbid(a6)
  401.     lea custom,a5
  402.     blitwait
  403.     
  404.     lea gfxname,a1
  405.     moveq #0,d0
  406.     jsr openlib(a6)    
  407.     move.l d0,a1
  408.     move.l oslist(a1),syscop1    ;store OS copper addrs
  409.     move.l oslist2(a1),syscop2
  410.     jsr closelib(a6)
  411.  
  412.     lea $64.w,a0
  413.     lea Oldvects,a1
  414.     moveq #7-1,d0
  415. vsavelp move.l (a0)+,(a1)+
  416.     dbf d0,vsavelp            ;Store OS vectors.
  417.     
  418.     move dmaconr(a5),Olddmacon    ;store DMA
  419.     move.w intreqr(a5),oldintreq
  420.     move.w intenar(a5),oldintena    ;store ints
  421.     move.w #$7fff,intena(a5)
  422.     move.w #$7fff,intreq(a5)    ;disable all ints    
  423.     catchVB
  424.     move.w #$7fff,dmacon(a5)    ;&dma
  425.     
  426.     lea newvects,a0
  427.     lea $64.w,a1
  428.     moveq #7-1,d0
  429. vloadlp    move.l (a0)+,(a1)+
  430.     dbf d0,vloadlp            ;load new handler vectors
  431.  
  432. ;Now setup the ciaa for keyboard...
  433.  
  434.     move.b ciaa+cra,Oldcra
  435.     move.b #%00010000,ciaa+cra    ;SP input, STOP & Forceload timerA
  436.     move.b ciaa+Talo,oldtal
  437.     move.b ciaa+Tahi,oldtah
  438.         
  439. ;Configure CIA-A for kboard...
  440.  
  441.     move.b #0,ciaa+cra        ;SP input...
  442.     move.b #%01111111,ciaa+icr    ;clear all cia ints
  443.     move.b #%10001000,ciaa+icr    ;SP int on
  444.     move.b ciaa+icr,d0        ;clear IRs
  445.  
  446.     move.w    #$c008,intena(a5)        
  447.     rts
  448.  
  449. *****************************************************************************
  450. * FREESYS will put the OS back together again... (Better had!)
  451. *****************************************************************************
  452.  
  453. freesys:
  454.     lea custom,a5
  455.     move #$7fff,intena(a5)
  456.     move #$7fff,intreq(a5)        ;disable all ints
  457.     move #$7fff,dmacon(a5)        ;& Dma
  458.  
  459.     move.b #0,ciaa+cra        ;reset ciaa...
  460.     move.b #%01111111,ciaa+icr
  461.     move.b #%10011011,ciaa+icr
  462.                     
  463.     move.b oldtal,ciaa+talo
  464.     move.b oldtah,ciaa+tahi
  465.     move.b oldcra,ciaa+cra
  466.  
  467.     lea oldvects,a0
  468.     lea $64.w,a1
  469.     moveq #7-1,d0
  470. vloslp    move.l (a0)+,(a1)+
  471.     dbf d0,vloslp            ;reset OS vectors
  472.  
  473.     catchvb
  474.     move.l syscop1,cop1lc(a5)
  475.     move.l syscop2,cop2lc(a5)
  476.     move #0,copjmp1(a5)
  477.     move #0,copjmp2(a5)        ;reset the copper
  478.  
  479.     move oldintena,d0
  480.     or #$c000,d0
  481.     move d0,intena(a5)        ;restore OS ints
  482.     move oldintreq,d0
  483.     or #$8000,d0
  484.     move d0,intreq(a5)
  485.     
  486.     catchVB
  487.     move olddmacon,d0
  488.     or #$8200,d0
  489.     move d0,dmacon(a5)        ;restore OS Dma
  490.  
  491.     move.l 4.w,a6
  492.     jsr permit(a6)
  493.     rts
  494.  
  495. *****************************************************************************
  496. * Unused Interrupt Drivers
  497. *****************************************************************************
  498.  
  499. LEV1:
  500. LEV2:
  501. LEV3:
  502. LEV4:
  503. LEV5:
  504. LEV6:
  505. LEV7:
  506.     rte
  507.  
  508. *******************************************************************
  509.         
  510. ;Offsets for OS routines....
  511.  
  512. Openlib    equ -30-522
  513. Closelib equ -414        ;...Equates for OS calls...
  514.  
  515. Forbid  equ -30-102
  516. Permit  equ -30-108
  517.  
  518. ciaapra = $bfe001
  519.  
  520. OsList        EQU    38
  521. OsList2        EQU     50
  522.  
  523. *******************************************************************
  524.  
  525. ;Equates for hardware registers
  526.  
  527. custom    EQU   $dff000
  528.  
  529. dmaconr    EQU   $002
  530. vposr    EQU   $004
  531. vhposr    EQU   $006
  532. intenar    EQU   $01C
  533. intreqr    EQU   $01E
  534.  
  535. vposw    EQU   $02A
  536. vhposw    EQU   $02C
  537.  
  538. cop1lc    EQU   $080
  539. cop2lc    EQU   $084
  540. copjmp1    EQU   $088
  541. copjmp2    EQU   $08A
  542. diwstrt    EQU   $08E
  543. diwstop    EQU   $090
  544. ddfstrt    EQU   $092
  545. ddfstop    EQU   $094
  546. dmacon    EQU   $096
  547. intena    EQU   $09A
  548. intreq    EQU   $09C
  549.  
  550. aud0vol    EQU   $0A8
  551. aud1vol EQU   $0B8
  552. aud2vol    EQU   $0C8
  553. aud3vol    EQU   $0D8
  554.  
  555. bpl1pth    EQU   $0E0
  556. bpl1ptl    EQU   $0E2
  557. bpl2pth    EQU   $0E4
  558. bpl2ptl    EQU   $0E6
  559. bpl3pth    EQU   $0E8
  560. bpl3ptl    EQU   $0EA
  561. bpl4pth    EQU   $0EC
  562. bpl4ptl    EQU   $0EE
  563. bpl5pth    EQU   $0F0
  564. bpl5ptl    EQU   $0F2
  565. bpl6pth    EQU   $0F4
  566. bpl6ptl    EQU   $0F6
  567.  
  568. bplcon0    EQU   $100
  569. bplcon1    EQU   $102
  570. bplcon2    EQU   $104
  571. bpl1mod    EQU   $108
  572. bpl2mod    EQU   $10A
  573.  
  574. spr0pth    EQU   $120
  575. spr0ptl EQU   $122
  576. spr1pth EQU   $124
  577. spr1ptl EQU   $126
  578. spr2pth    EQU   $128
  579. spr2ptl EQU   $12A
  580. spr3pth EQU   $12C
  581. spr3ptl EQU   $12E
  582. spr4pth    EQU   $130
  583. spr4ptl EQU   $132
  584. spr5pth EQU   $134
  585. spr5ptl EQU   $136
  586. spr6pth    EQU   $138
  587. spr6ptl EQU   $13A
  588. spr7pth EQU   $13C
  589. spr7ptl EQU   $13E
  590.  
  591. col0    EQU   $180
  592. col1     EQU   $182
  593. col2    EQU   $184
  594. col3    EQU   $186
  595. col4    EQU   $188
  596. col5    equ   $18a
  597. col6    equ   $18c
  598. col7    equ   $18e
  599. col8    EQU   $190
  600. col9    equ   $192
  601. col10    equ   $194
  602. col11    equ   $196
  603. col12    equ   $198
  604. col13    equ   $19a
  605. col14    equ   $19c
  606. col15    equ   $19e
  607. col16   equ   $1A0    
  608. col17    equ   $1a2
  609. col18   equ   $1a4
  610. col19   equ   $1a6
  611. col20   equ   $1a8
  612. col21   equ   $1aa
  613. col22   equ   $1ac
  614. col23   equ   $1ae
  615. col24   equ   $1b0
  616. col25   equ   $1b2
  617. col26   equ   $1b4
  618. col27   equ   $1b6
  619. col28   equ   $1b8
  620. col29   equ   $1ba
  621. col30   equ   $1bc
  622. col31   equ   $1be
  623.  
  624. ciaa     equ     $bfe001
  625. ciab    equ    $bfd000
  626.  
  627. pra    EQU    $0000
  628. prb    EQU    $0100
  629. ddra    EQU    $0200
  630. ddrb    EQU    $0300
  631. talo    EQU    $0400
  632. tahi    EQU    $0500
  633. tblo    EQU    $0600
  634. tbhi    EQU    $0700
  635. todlow    EQU    $0800
  636. todmid    EQU    $0900
  637. todhi    EQU    $0A00
  638. sp    EQU    $0C00
  639. icr    EQU    $0D00
  640. cra    EQU    $0E00
  641. crb    EQU    $0F00
  642.  
  643. *******************************************************************
  644.  
  645. planesize    equ    40*256
  646.  
  647. timer:    dc.l    0
  648.     
  649. *******************************************************************
  650.  
  651. piccy:
  652.         ;incbin    "dh0:mm/piccy"
  653.  
  654.         ;to include a picture here, just replace the
  655.         ;above INCBIN with one of your own, specifying the
  656.         ;correct pathname for the picture. The picture 
  657.         ;must be in RAW format, not IFF.
  658.         
  659. *******************************************************************
  660.  
  661.     end  
  662.  
  663.